package pl.enigmatic.math;

import java.util.List;
import java.util.Vector;


public class MarkedSubrangeList<X> extends Vector<X> {

	/** */
	private static final long serialVersionUID = 1L;

	public static void main(String[] args) {
		MarkedSubrangeList<String> map = new MarkedSubrangeList<String>();
		map.useRelativeOffsets(1, 1);
		System.out.println(map.getSpecialRange());
	}

	private int left = 0;
	private int right = 0;
	private int length = 0;
	private boolean countFromLeft = true;
	private boolean useLength = false;

	public void useConstantLength(boolean fromLeft, int offset, int length) {
		this.length = length;
		useLength = true;
		countFromLeft = fromLeft;
		if (countFromLeft) {
			left = offset;
		} else {
			right = offset;
		}
	}

	public void useRelativeOffsets(int left, int right) {
		useLength = false;
		this.left = left;
		this.right = right;
	}

	public synchronized List<X> getSpecialRange() {
		int fromIndex = left;
		int toIndex = size() - right;
		if (useLength) {
			if (countFromLeft) {
				toIndex = fromIndex + length;
			} else {
				fromIndex = toIndex - length;
			}
		}
		if (fromIndex < toIndex) return subList(fromIndex, toIndex);
		else
			return new Vector<X>();
	}

}
